package fire.and.near.challenger.database;

import android.content.Context;
import android.content.SharedPreferences;

public class ProfileManager {
	private Context context = null;
	public static final String FILENAME = "Profile";
	public static final String FB_ID = "fbid";
	public static final String USERNAME = "username";
	public static final String PASSWORD = "password";

	public ProfileManager(Context context) {
		this.setContext(context);
	}

	public boolean login(String username, String password) {
		SharedPreferences sharedPrefs = context.getSharedPreferences(FILENAME,
				Context.MODE_PRIVATE);
		return username.equals(sharedPrefs.getString(USERNAME, null))
				&& password.equals(sharedPrefs.getString(PASSWORD, null));
	}

	public boolean register(long fbID, String username, String password) {
		SharedPreferences sharedPrefs = context.getSharedPreferences(FILENAME,
				Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = sharedPrefs.edit();
		editor.putLong(FB_ID, fbID);
		editor.putString(USERNAME, username);
		editor.putString(PASSWORD, password);
		return editor.commit();
	}

	public long getFbId() {
		SharedPreferences sharedPrefs = context.getSharedPreferences(FILENAME,
				Context.MODE_PRIVATE);
		return sharedPrefs.getLong(FB_ID, -1);
	}
	
	public boolean setFbId(long fbID) {
		SharedPreferences sharedPrefs = context.getSharedPreferences(FILENAME,
				Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = sharedPrefs.edit();
		editor.putLong(FB_ID, fbID);
		
		return editor.commit();
	}

	public String getUsername() {
		SharedPreferences sharedPrefs = context.getSharedPreferences(FILENAME,
				Context.MODE_PRIVATE);
		return sharedPrefs.getString(USERNAME, null);
	}
	
	public boolean setUsername(String username) {
		SharedPreferences sharedPrefs = context.getSharedPreferences(FILENAME,
				Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = sharedPrefs.edit();
		editor.putString(USERNAME, username);
		
		return editor.commit();
	}
	
	public String getPassword() {
		SharedPreferences sharedPrefs = context.getSharedPreferences(FILENAME,
				Context.MODE_PRIVATE);
		return sharedPrefs.getString(PASSWORD, null);
	}
	
	public boolean setPassword(String password) {
		SharedPreferences sharedPrefs = context.getSharedPreferences(FILENAME,
				Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = sharedPrefs.edit();
		editor.putString(PASSWORD, password);
		
		return editor.commit();
	}

	public Context getContext() {
		return context;
	}

	public void setContext(Context context) {
		this.context = context;
	}
}
